﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Medianamik.Core;
using Medianamik.Core.ImportExport;
using System.IO;

namespace Medianamik.UI.ImportExportManagement
{
    public partial class ExportNodes : Medianamik.UI.BasePage 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                       
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid && ExportDatePicker.SelectedDate.HasValue )
            {
               var serializer = new Medianamik.Core.ImportExport.JSonNodeDataSourceSerializer();
               Medianamik2NodeDataSource source = new Medianamik2NodeDataSource(new NodeFilter().CreatedSince(ExportDatePicker.SelectedDate.Value ));

               var data = source.GetData();

               NodeCountLabel.Text = "NodeCount: " + data.Records.Count; 

               StringWriter writer = new StringWriter();
               serializer.Serialize(data, writer);
              txtJson.Text = writer.ToString();

            }
        }
    }

    

}
